﻿Public Class MASACCEPTM
    Dim PROVIDER_Check As New PROVIDERSCLASS
    Dim connect As CONDB = CONDB.NewConnection()
    Dim dtsetMasacceptm As DataSet

    Public Sub queryMasacceptm()
        dtsetMasacceptm = New DTSETMASACCEPTM

        Dim objGetMasacceptm As New MASACCEPTMCLASS
        Dim sql As String = objGetMasacceptm.selectMasacceptm_
        connect.GetTable(sql, dtsetMasacceptm.Tables("masacceptm"))

        connect.Dispose()

        xgvMasacceptm.DataSource = dtsetMasacceptm
        xgvMasacceptm.ForceInitialize()
    End Sub

    Private Sub MASACCEPTM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        queryMasacceptm()

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub GridView1_RowClick(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowClickEventArgs) Handles GridView1.RowClick
        txtAccmid.Text = GridView1.GetDataRow(GridView1.FocusedRowHandle)("accmid").ToString()
        txtAccm_name.Text = GridView1.GetDataRow(GridView1.FocusedRowHandle)("accm_name").ToString()
        txtAccm_name_en.Text = GridView1.GetDataRow(GridView1.FocusedRowHandle)("accm_name_en").ToString()

        If GridView1.GetDataRow(GridView1.FocusedRowHandle)("status") IsNot DBNull.Value Then
            ckbStatus.Checked = Convert.ToBoolean(GridView1.GetDataRow(GridView1.FocusedRowHandle)("status"))
        Else
            ckbStatus.Checked = False
        End If
    End Sub

    Private Sub btnAdddata_Click(sender As Object, e As EventArgs) Handles btnAdddata.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If txtAccm_name.Text.Length.ToString > 0 And txtAccm_name_en.Text.Length.ToString > 0 Then
                    Dim objAddMasacceptm As New MASACCEPTMCLASS
                    objAddMasacceptm.ACCM_NAME_ = txtAccm_name.Text.Trim
                    objAddMasacceptm.ACCM_NAME_EN_ = txtAccm_name_en.Text.Trim
                    objAddMasacceptm.STATUS_ = ckbStatus.Checked

                    If objAddMasacceptm.insertMassacceptm = True Then
                        queryMasacceptm()
                        clearForm()
                    End If
                Else
                    MsgBox("ท่านต้องระบุข้อมูลชื่อการรับเงินให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub btnEditData_Click(sender As Object, e As EventArgs) Handles btnEditData.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                Dim editStat As Integer
                editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลการรับเงินดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                If editStat = 1 Then
                    If txtAccmid.Text.Length.ToString > 0 And txtAccm_name.Text.Length.ToString > 0 And txtAccm_name_en.Text.Length.ToString > 0 Then
                        Dim objEditMasacceptm As New MASACCEPTMCLASS
                        objEditMasacceptm.ACCMID_ = txtAccmid.Text
                        objEditMasacceptm.ACCM_NAME_ = txtAccm_name.Text.Trim
                        objEditMasacceptm.ACCM_NAME_EN_ = txtAccm_name_en.Text.Trim
                        objEditMasacceptm.STATUS_ = ckbStatus.Checked

                        If objEditMasacceptm.editMasacceptm = True Then
                            queryMasacceptm()
                            clearForm()
                        End If
                    Else
                        MsgBox("ท่านต้องระบุข้อมูลชื่อการรับเงินให้ครบถ้วน")
                    End If
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masacceptm")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masacceptm")
        nextform.ShowDialog()
    End Sub

    Private Sub clearForm()
        txtAccmid.Clear()
        txtAccm_name.Clear()
        txtAccm_name_en.Clear()
        ckbStatus.Checked = False
    End Sub
End Class